package com.easyadmin.modules.stock.controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;


import com.easyadmin.common.aop.annotation.Repeat;
import com.easyadmin.common.web.base.BaseController;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.common.web.domain.response.Result;
import com.easyadmin.common.web.domain.response.module.ResultTable;
import com.easyadmin.modules.stock.domain.SysInvestRulesEntity;
import com.easyadmin.modules.stock.domain.SysModelStrategyEntity;
import com.easyadmin.modules.stock.service.SysModelStrategyService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


/**
 * 股票策略表
 *
 * @author wanzenghui
 * @email lemon_wan@aliyun.com
 * @date 2025-04-03 20:54:57
 */
@RestController
@RequestMapping("/stock/strategy")
public class SysModelStrategyController extends BaseController {

    @Autowired
    private SysModelStrategyService sysModelStrategyService;

    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "stock/strategy/";

    /**
     * Describe: 获取列表视图
     * Param ModelAndView
     * Return 列表视图
     */
    @GetMapping("main")
    @ApiOperation(value = "分页列表视图")
    @PreAuthorize("hasPermission('/stock/strategy/main','stock:strategy:main')")
    public ModelAndView main() {
        return jumpPage(MODULE_PATH + "main");
    }

    /**
     * Describe: 获取新增视图
     * Param ModelAndView
     * Return 新增视图
     */
    @GetMapping("add")
    @ApiOperation(value = "新增视图")
    @PreAuthorize("hasPermission('/stock/strategy/add','stock:strategy:add')")
    public ModelAndView add() {
        return jumpPage(MODULE_PATH + "add");
    }

    /**
     * 分页查询
     */
    @ResponseBody
    @GetMapping("/list")
    @PreAuthorize("hasPermission('/stock/strategy/list','stock:strategy:list')")
    public ResultTable list(@ModelAttribute SysModelStrategyEntity sysInvestRulesEntity, PageDomain pageDomain) {
        PageInfo<SysModelStrategyEntity> pageInfo = sysModelStrategyService.queryPage(sysInvestRulesEntity, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }



    /**
     * Describe: 保存期货信息
     * Param SysRole
     * Return 执行结果
     */
    @Repeat
    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    @PreAuthorize("hasPermission('/stock/strategy/add','stock:strategy:add')")
    public Result save(@RequestBody SysModelStrategyEntity sysInvestRulesEntity) {
        sysInvestRulesEntity.setCreateDate(LocalDateTime.now());
        return decide(sysModelStrategyService.save(sysInvestRulesEntity));
    }




    /**
     * Describe: 获取修改视图
     * Param ModelAndView
     * Return 修改视图
     */
    @GetMapping("edit")
    @ApiOperation(value = "获取修改视图")
    @PreAuthorize("hasPermission('/stock/strategy/edit','stock:strategy:edit')")
    public ModelAndView edit(ModelAndView modelAndView, String id) {
        modelAndView.addObject("stockStrategy", sysModelStrategyService.getById(id));
        modelAndView.setViewName(MODULE_PATH + "edit");
        return modelAndView;
    }



    /**
     * Describe: 修改信息
     * Param SysRole
     * Return 执行结果
     */
    @PutMapping("update")
    @ApiOperation(value = "修改数据")
    @PreAuthorize("hasPermission('/stock/strategy/edit','stock:strategy:edit')")
    public Result update(@RequestBody SysModelStrategyEntity sysInvestRulesEntity) {
        return decide(sysModelStrategyService.update(sysInvestRulesEntity));
    }

    /**
     * Describe: 批量删除接口
     * Param: ids
     * Return: Result
     */
    @DeleteMapping("batchRemove/{ids}")
    @ApiOperation(value = "批量删除数据")
    @PreAuthorize("hasPermission('/stock/strategy/remove','stock:strategy:remove')")
    public Result batchRemove(@PathVariable String ids) {
        return decide(sysModelStrategyService.batchRemove(ids.split(",")));
    }

}
